﻿using System.Configuration;
using System.Data;
using System.Runtime.CompilerServices;
using System.Windows;
using Clipboard.Services;
using Clipboard.Tools;
using Clipboard.ViewModel;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

namespace Clipboard
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        public static IHost AppHost { get; private set; }
        public App()
        {
            AppHost = Host.CreateDefaultBuilder()
                .ConfigureServices((context, services) =>
                {
                    // 数据库连接字符串

                    // 注册 SqlSugar
                    services.AddSingleton(new SqlSugarHelper());

                    // 注册 ClipboardViewModel
                    services.AddSingleton<ClipboardViewModel>();

                    // 注册 LoginViewModel
                    services.AddSingleton<LoginViewModel>();

                    // 注册 MainWindow
                    services.AddTransient<MainWindow>();

                    // 注册 LoginWindow
                    //services.AddTransient<LoginWindow>();
                })
                .Build();
        }


        private MainWindow _mainWindow;
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            // 获取主窗口实例并显示
            _mainWindow = AppHost.Services.GetRequiredService<MainWindow>();
            _mainWindow.Show();
           
           
        }

    }

}
